<?php
session_start();
ob_start();
include_once 'include/common.php';
$core = new core();
if (!$core->CheckLogin()) {
    header('Location:login.php');
}
$customer_order_id = isset($_GET["id"]) ? intval($_GET["id"]) : 0;
$customer_order = $core->getZenCustomerOrderById($customer_order_id);
if (!$customer_order) {
    header("location: zenOrderList.php");
}
$customer = $core->getCustomerById($customer_order->customer_id);
$list_payment = $core->getListPaymentByCustomerOrder($customer_order_id);
//get order name
$order_data = $core->getOrderById($customer_order->zen_order_id);
$order_name = $order_data->zen_order_name;
//get info other order
$other_order = $core->getOtherOrderByCustomerId($customer_order->customer_id, $customer_order_id);
?>
<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>Zen store</title>
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="description" content="Charisma, a fully featured, responsive, HTML5, Bootstrap admin template.">
        <meta name="author" content="Muhammad Usman">

        <!-- The styles -->
        <link id="bs-css" href="css/bootstrap-cerulean.css" rel="stylesheet">
        <style type="text/css">
            body {
                padding-bottom: 40px;
            }
            .sidebar-nav {
                padding: 9px 0;
            }
        </style>
        <!--        <link href="css/bootstrap-responsive.css" rel="stylesheet">
                <link href="css/charisma-app.css" rel="stylesheet">
                <link href="css/style.css" rel="stylesheet">
                <link href="css/jquery-ui-1.8.21.custom.css" rel="stylesheet">
        
                <link href='css/chosen.css' rel='stylesheet'>
                <link href='css/uniform.default.css' rel='stylesheet'>
        
                <link href='css/jquery.cleditor.css' rel='stylesheet'>
        
        
                <link href='css/jquery.iphone.toggle.css' rel='stylesheet'>
        
                <link href='css/uploadify.css' rel='stylesheet'>-->
        <link href="css/bootstrap-responsive.css" rel="stylesheet">
        <link href="css/charisma-app.css" rel="stylesheet">
        <link href="css/jquery-ui-1.8.21.custom.css" rel="stylesheet">
        <link href='css/fullcalendar.css' rel='stylesheet'>
        <link href='css/fullcalendar.print.css' rel='stylesheet'  media='print'>
        <link href='css/chosen.css' rel='stylesheet'>
        <link href='css/uniform.default.css' rel='stylesheet'>
        <link href='css/colorbox.css' rel='stylesheet'>
        <link href='css/jquery.cleditor.css' rel='stylesheet'>
        <link href='css/jquery.noty.css' rel='stylesheet'>
        <link href='css/noty_theme_default.css' rel='stylesheet'>
        <link href='css/elfinder.min.css' rel='stylesheet'>
        <link href='css/elfinder.theme.css' rel='stylesheet'>
        <link href='css/jquery.iphone.toggle.css' rel='stylesheet'>
        <link href='css/opa-icons.css' rel='stylesheet'>
        <link href='css/uploadify.css' rel='stylesheet'>
        <link href="css/style.css" rel="stylesheet">
        <!-- The HTML5 shim, for IE6-8 support of HTML5 elements -->
        <!--[if lt IE 9]>
          <script src="http://html5shim.googlecode.com/svn/trunk/html5.js"></script>
        <![endif]-->

        <!-- The fav icon -->
        <link rel="shortcut icon" href="img/favicon.ico">

    </head>

    <body>
        <div id="page-wrap" class="page-wrap body-wrap ">
            <div id="page-tray" class="tray transition">
                <?php include_once ('new_menu.php'); ?>

                <div id="page-content" class="page-content transition profile-page">
                    <?php include_once ('navbar.php'); ?>
                    <div class="container-fluid">
                        <div class="row-fluid">
                            <div id="content" class="span12">   
<!--                                <div>
                                    <ul class="breadcrumb">
                                        <li>
                                            <a href="#">Home</a> <span class="divider">/</span>
                                        </li>
                                        <li>
                                            <a href="#">Thanh toán</a>
                                        </li>
                                    </ul>
                                </div>-->

                                <div class="row-fluid sortable">
                                    <div class="box span12">
                                        <div class="box-header well" data-original-title>
                                            <h2><i class="icon-edit"></i> Thanh toán</h2>

                                        </div>
                                        <div class="box-content">
                                            <form class="form-horizontal">
                                                <fieldset>
                                                    <div class="control-group">
                                                        <label class="control-label" ></label>
                                                        <div class="controls">
                                                            <div class="alert alert-error" id="alert-error-payment" style="display:none">
                                                            </div>
                                                            <div class="alert alert-success" id="alert-success-payment" style="display:none"></div>
                                                        </div>
                                                    </div>

                                                    <div class="control-group">
                                                        <label class="control-label" for="">Tên khách hàng </label>
                                                        <div class="controls">
                                                            <input type="text" class="span6 typeahead" readonly value="<?php echo $customer->facebook_name; ?>"  >



                                                        </div>
                                                    </div>
                                                    <div class="control-group">
                                                        <label class="control-label" for="type_payment">Cách thanh toán </label>
                                                        <div class="controls">
                                                            <select id="type_payment">
                                                                <option value="2">Cọc VCB</option>
                                                                <option value="1">Cọc trực tiếp</option>
                                                                <option value="3">Refund VCB</option>
                                                                <option value="4">Refund trực tiếp</option>
                                                            </select>

                                                        </div>
                                                    </div>
                                                    <div class="control-group">
                                                        <label class="control-label" for="payment">Số tiền đặt cọc </label>
                                                        <div class="controls">
                                                            <input type="text" class="span6 typeahead" id="payment" style='display:inline-block' ><div style=' margin-left: 5px;display:inline-block'>.000 VNĐ</div>

                                                        </div>
                                                    </div>
                                                    <div class="control-group">
                                                        <label class="control-label" for="payment_date">Ngày đặt cọc </label>
                                                        <div class="controls">
                                                            <input type="text" class="input-xlarge datepicker" id="payment_date" value="02/16/12">

                                                        </div>
                                                    </div>
                                                    <div class="control-group">
                                                        <label class="control-label" for="payment_description">Ghi chú </label>
                                                        <div class="controls">
                                                            <textarea name="product_description" id="payment_description"></textarea>

                                                        </div>
                                                    </div>
                                                    <div class="form-actions">
                                                        <button type="button" class="btn btn-primary" id="save_payment">Save changes</button>
                                                        <button type="reset" class="btn" id="reset">Cancel</button>
                                                    </div>
                                                </fieldset>
                                            </form>   

                                        </div>
                                    </div><!--/span-->

                                </div><!--/row-->
                                <div class="row-fluid sortable">		
                                    <div class="box span12">
                                        <div class="box-header well" data-original-title>
                                            <h2><i class="icon-user"></i>Lịch sử thanh toán</h2>

                                        </div>
                                        <input type="hidden" name="payment_id" id="payment_id" value="0">
                                        <input type="hidden" name="customer_order_id" id="customer_order_id" value="<?php echo $customer_order_id; ?>">
                                        <div class="box-content" id="box_content_customer_order_payment" style="height: 400px;">


                                            <table class="table table-striped table-bordered bootstrap-datatable datatable" id="table_customer_order">
                                                <thead>
                                                    <tr>
                                                        <th>Ngày thanh toán</th>
                                                        <th>Kiểu thanh toán</th>
                                                        <th>Mô tả</th>
                                                        <th>Số tiền<br/>(*1000 VND)</th>
                                                        <th>Actions</th>
                                                    </tr>
                                                </thead>   
                                                <tbody id="tbody_payment_list">
                                                    <?php
                                                    if ($list_payment) {
                                                        foreach ($list_payment as $payment) {
                                                            ?>
                                                            <tr>
                                                                <td class="center" ><?php echo date('d-m-Y', strtotime($payment->date_payment)); ?></td>
                                                                <td class="center">
                                                                    <?php
                                                                    switch ($payment->type_payment) {
                                                                        case 1:
                                                                            echo "Cọc trực tiếp";
                                                                            break;

                                                                        case 2:
                                                                            echo "Cọc VCB";
                                                                            break;
                                                                        case 3:
                                                                            echo "Refund VCB";
                                                                            break;
                                                                        case 4:
                                                                            echo "Refund trực tiếp";
                                                                            break;
                                                                    }
                                                                    ?>
                                                                </td>
                                                                <td class="center"><?php echo $payment->description; ?></td>
                                                                <td class="center"><?php echo number_format($payment->payment / 1000); ?></td>
                                                                <td class="center" >
                                                                    <a class="btn btn-info btn_edit_payment" href="javascript:void(0)" rel="<?php echo $payment->id; ?>">
                                                                        <i class="icon-edit icon-white"></i>  
                                                                        Edit                                            
                                                                    </a>
                                                                    <a href="javascript:void(0)" class="btn btn-danger btn_delete_payment" rel="<?php echo $payment->id; ?>">
                                                                        <i class="icon-trash icon-white"></i> 
                                                                        Delete
                                                                    </a>
                                                                </td>
                                                            </tr>
                                                            <?php
                                                        }
                                                    }
                                                    ?>
                                                    <tr><td colspan="3" style='text-align:right'>Tổng tiền cọc:</td><td colspan="2"><?php echo number_format($customer_order->total_payment); ?></td></tr>
                                                </tbody>
                                            </table>
                                            <table class="table table-bordered " id="table_calculator_payment">
                                                <tr><th>Thanh toán</th><th>Đơn vị<br/>(*1000 VND)</th></tr>
                                                <tr><td>Tổng tiền đơn hàng <?php echo $order_name; ?>:</td><td><?php echo number_format($customer_order->total_order_money / 1000); ?></td></tr>
                                                <tr><td>Tổng cọc:</td><td><?php echo number_format($customer_order->total_payment / 1000); ?></td></tr>

                                                <?php
                                                if ($customer_order->total_current_money > 0) {
                                                    ?>
                                                    <tr><td><b><?php echo $order_name; ?> còn thừa:</b></td><td><?php echo number_format($customer_order->total_current_money / 1000); ?></td></tr>
                                                    <?php
                                                } elseif ($customer_order->total_current_money < 0) {
                                                    ?>
                                                    <tr><td><b><?php echo $order_name; ?> còn nợ:</b></td><td><?php echo number_format($customer_order->total_current_money / 1000); ?></td></tr>
                                                    <?php
                                                }
                                                ?>
                                                <?php
                                                $total_other_money = $customer_order->total_current_money;
                                                if ($other_order) {

                                                    foreach ($other_order as $date_order) {
                                                        $total_other_money = $total_other_money + $date_order->total_current_money;
                                                        if ($date_order->total_current_money > 0) {
                                                            ?>
                                                            <tr><td><?php echo $date_order->zen_order_name; ?> còn thừa:</td><td><?php echo number_format($date_order->total_current_money / 1000); ?></td></tr>
                                                            <?php
                                                        } elseif ($date_order->total_current_money < 0) {
                                                            ?>
                                                            <tr><td><?php echo $date_order->zen_order_name; ?> còn thiếu:</td><td><?php echo number_format($date_order->total_current_money / 1000); ?></td></tr>
                                                            <?php
                                                        }
                                                    }
                                                    ?>
                                                    <?php
                                                    if ($total_other_money > 0) {
                                                        ?>
                                                        <tr><td><b>Tổng tiền của khách <?php echo $customer->facebook_name; ?> :</b></td><td><?php echo number_format($total_other_money / 1000); ?>(còn thừa)</td></tr>
                                                        <?php
                                                    } else {
                                                        ?>
                                                        <tr><td><b>Tổng tiền của khách <?php echo $customer->facebook_name; ?> :</b></td><td><?php echo number_format($total_other_money / 1000); ?>(còn nợ)</td></tr>
                                                        <?php
                                                    }
                                                }
                                                ?>
                                            </table>
                                            <div id="loading" style="display:none;width: 220px; height: 19px;margin: 0 auto;"><img title="img/ajax-loaders/ajax-loader-7.gif" src="img/ajax-loaders/ajax-loader-7.gif"></div>
                                        </div>
                                    </div><!--/span-->

                                </div><!--/row-->
                            </div><!--/#content.span10-->

                        </div><!--/fluid-row-->
                        <?php include_once ('footer.php'); ?>

                    </div><!--/.fluid-container-->
                </div>
            </div>
        </div>

        <!-- external javascript
        ================================================== -->
        <!-- Placed at the end of the document so the pages load faster -->

        <!-- jQuery -->
        <script src="js/jquery-1.7.2.min.js"></script>
        <!-- jQuery UI -->
        <script src="js/jquery-ui-1.8.21.custom.min.js"></script>
        <!-- transition / effect library -->
        <script src="js/bootstrap-transition.js"></script>
        <!-- alert enhancer library -->
        <script src="js/bootstrap-alert.js"></script>
        <!-- modal / dialog library -->
        <script src="js/bootstrap-modal.js"></script>
        <!-- custom dropdown library -->
        <script src="js/bootstrap-dropdown.js"></script>
        <!-- scrolspy library -->
        <script src="js/bootstrap-scrollspy.js"></script>
        <!-- library for creating tabs -->
        <script src="js/bootstrap-tab.js"></script>
        <!-- library for advanced tooltip -->
        <script src="js/bootstrap-tooltip.js"></script>
        <!-- popover effect library -->
        <script src="js/bootstrap-popover.js"></script>
        <!-- button enhancer library -->
        <script src="js/bootstrap-button.js"></script>
        <!-- accordion library (optional, not used in demo) -->
        <script src="js/bootstrap-collapse.js"></script>
        <!-- carousel slideshow library (optional, not used in demo) -->
        <script src="js/bootstrap-carousel.js"></script>
        <!-- autocomplete library -->
        <script src="js/bootstrap-typeahead.js"></script>
        <!-- tour library -->
        <script src="js/bootstrap-tour.js"></script>
        <!-- library for cookie management -->
        <script src="js/jquery.cookie.js"></script>
        <!-- calander plugin -->
        <script src='js/fullcalendar.min.js'></script>
        <!-- data table plugin -->
        <script src='js/jquery.dataTables.min.js'></script>

        <!-- chart libraries start -->
        <script src="js/excanvas.js"></script>
        <script src="js/jquery.flot.min.js"></script>
        <script src="js/jquery.flot.pie.min.js"></script>
        <script src="js/jquery.flot.stack.js"></script>
        <script src="js/jquery.flot.resize.min.js"></script>
        <!-- chart libraries end -->

        <!-- select or dropdown enhancer -->
        <script src="js/jquery.chosen.min.js"></script>
        <!-- checkbox, radio, and file input styler -->
        <script src="js/jquery.uniform.min.js"></script>
        <!-- plugin for gallery image view -->
        <script src="js/jquery.colorbox.min.js"></script>
        <!-- rich text editor library -->
        <script src="js/jquery.cleditor.min.js"></script>
        <!-- notification plugin -->
        <script src="js/jquery.noty.js"></script>
        <!-- file manager library -->
        <script src="js/jquery.elfinder.min.js"></script>
        <!-- star rating plugin -->
        <script src="js/jquery.raty.min.js"></script>
        <!-- for iOS style toggle switch -->
        <script src="js/jquery.iphone.toggle.js"></script>
        <!-- autogrowing textarea plugin -->
        <script src="js/jquery.autogrow-textarea.js"></script>
        <!-- multiple file upload plugin -->
        <script src="js/jquery.uploadify-3.1.min.js"></script>
        <!-- history.js for cross-browser state change on ajax -->
        <script src="js/jquery.history.js"></script>
        <!-- application script for Charisma demo -->
        <script src="js/common.js?t=6"></script>
        <script src="js/addPayment.js?t=6"></script>



    </body>
</html>

